$(document).ready(function() {
	var tid1 = 0;
	var toid1 = 0;
	
	function t(){  
	var tid=$(window.parent.frames["taskRequestFrame"].document).find('#savetid').text();
	var toid=$(window.parent.frames["taskRequestFrame"].document).find('#savetoid').text();
	tid1=tid;
	toid1=toid;
//	alert(toid1);
	}
	
	window.setTimeout(t,1000); 
	
	
	function s(){ 
//	alert("over or reqs taskid "+tid1);
	$.ajax({
			type : "post",
			url : "lzw/TaskOver_directToApply.action?taskid="+tid1+"&toid="+toid1,
			success : showData				
       });
	}
	
	window.setTimeout(s,1000); 
	
	function showData(data){
//		alert("rightString="+data.rightString);
	    if(data.rightString=="noRecord"){          //无记录
			$("#banjiebiao").hide();
			alert("暂无任务需要处理！");
		}	
		else if(data.rightString=="dircetor_to_over"){         //指挥长办结自己的任务
			if(!confirm("你要办结该任务吗？"))
			{
			return;
			}else{
			$("#banjiebiao").show();
		    $("#shenqingren").hide();
			$("#banjiedanhao").hide();
			//$("#getbackdiv").hide();
			$("#banjierenheshijian").show();
			$("#chuzhi").show();
			$("#banjiebutton").hide();
			$("#requestdiv").show();              
			//$("#requestdiv2").hide();
			$("#tijiao").hide();
			$("#shenqingshijian").hide();
			$("#shenqingliyou").hide();
			
//			$("#toid").text(data.tboverRequest.toId);
			$("#tName").text(data.name);
			$("#tContext").text(data.tcontext);
			$("#tId").text(data.tid);
//			$("#applyPerson").text(data.tboverRequest.c);
			$("#tPerson").text(data.cuname);
			var nowTime = new Date();
			$("#tTime").text(nowTime.toLocaleString());     //new 一个js 时间填充
//			$("#reason").text(data.tboverRequest.toReason);			
            }
//			$("#advice").text(data.tboverRequest.tbTask.THandeled);
		}
	    else if(data.rightString=="show_the_record"){         //显示退办后的，指挥长再次办结
			$("#banjiebiao").show();
			$("#banjiedanhao").show();
			//$("#getbackdiv").hide();
			$("#shenqingren").show();
			$("#banjierenheshijian").show();
			$("#chuzhi").show();
			$("#banjiebutton").hide();
			$("#requestdiv").show();           //指挥长对其进行直接办结
			//$("#requestdiv2").hide();
			$("#tijiao").hide();
			$("#shenqingliyou").show();
			$("#shenqingshijian").hide();
			
			$("#toid").text(data.tboverRequest.toId);
			$("#tName").text(data.tboverRequest.tbTask.TName);
			$("#tContext").text(data.tboverRequest.tbTask.TContext);
			$("#tId").text(data.tboverRequest.tbTask.TId);
			$("#applyPerson").text(data.tboverRequest.c);
			$("#tPerson").text(data.tboverRequest.b);
			
			$("#tTime").text(data.tboverRequest.toTime.replace(/T/," "));
			$("#reason").text(data.tboverRequest.toReason);			
			$("#advice").text(data.tboverRequest.toFailue);
		}
		else if(data.rightString=="read_task_over_request"){  //只能看到办结申请表
			$("#banjiebiao").show();
			$("#banjiedanhao").show();
			$("#shenqingren").show();
			//$("#getbackdiv").hide();
			$("#banjierenheshijian").hide();
			$("#chuzhi").hide();
			$("#banjiebutton").hide();
			$("#requestdiv").hide();
			//$("#requestdiv2").hide();
			$("#tijiao").hide();
			$("#shenqingliyou").show();
			$("#shenqingshijian").show();
			
			$("#toid").text(data.tboverRequest.toId);
			$("#tName").text(data.tboverRequest.tbTask.TName);
			$("#tContext").text(data.tboverRequest.tbTask.TContext);
			$("#tId").text(data.tboverRequest.tbTask.TId);
			$("#applyPerson").text(data.tboverRequest.c);
//			$("#tPerson").text(data.cuname);
			
			$("#applyTime").text(data.tboverRequest.toTime.replace(/T/," "));
			$("#reason").text(data.tboverRequest.toReason);
//			$("#advice").text(data.tboverRequest.toReason);
		}else if(data.rightString=="Overback"){         //退办的
			$("#banjiebiao").show();
			$("#banjiedanhao").show();
			//$("#getbackdiv").hide();
			$("#shenqingren").show();
			$("#shenqingliyou").show();
			$("#banjierenheshijian").show();
			$("#chuzhi").show();
			$("#banjiebutton").hide();
			$("#requestdiv").hide();
			//$("#requestdiv2").hide();
			$("#tijiao").hide();
			$("#shenqingshijian").hide();
			
			$("#toid").text(data.tboverRequest.toId);
			$("#tName").text(data.tboverRequest.tbTask.TName);
			$("#tContext").text(data.tboverRequest.tbTask.TContext);
			$("#tId").text(data.tboverRequest.tbTask.TId);
			$("#applyPerson").text(data.tboverRequest.c);
			$("#tPerson").text(data.tboverRequest.b);
			
			$("#tTime").text(data.tboverRequest.toTime.replace(/T/," "));
			$("#reason").text(data.tboverRequest.toReason);			
			$("#advice").text(data.tboverRequest.toFailue);                                     
		}else if(data.rightString=="Oversuccess"){         //办结成功的
			if(data.tboverRequest.toReason=="null"){
				$("#shenqingliyou").hide();
				$("#shenqingren").hide();
			}else{
				$("#shenqingliyou").show();
				$("#reason").text(data.tboverRequest.toReason);	
				$("#shenqingren").show();
			}
			$("#banjiebiao").show();
			$("#banjiedanhao").show();
			//$("#getbackdiv").hide();
			$("#banjierenheshijian").show();
			$("#chuzhi").show();
			$("#banjiebutton").hide();
			$("#requestdiv").hide();
			//$("#requestdiv2").hide();
			$("#tijiao").hide();
			$("#shenqingshijian").hide();
			
			$("#toid").text(data.tboverRequest.toId);
			$("#tName").text(data.tboverRequest.tbTask.TName);
			$("#tContext").text(data.tboverRequest.tbTask.TContext);
			$("#tId").text(data.tboverRequest.tbTask.TId);
			$("#applyPerson").text(data.tboverRequest.c);
			$("#tPerson").text(data.tboverRequest.b);		
			$("#tTime").text(data.tboverRequest.toTime.replace(/T/," "));					
			$("#advice").text(data.tboverRequest.tbTask.THandeled);
		}else if(data.rightString=="ok"){         //可办结
			$("#banjiebiao").show();
			$("#banjiedanhao").show();
			//$("#getbackdiv").hide();
			$("#shenqingren").show();
			$("#shenqingliyou").show();
			$("#banjierenheshijian").show(); 
			$("#chuzhi").show();
			$("#banjiebutton").show();
			$("#requestdiv").hide();
			//$("#requestdiv2").hide();
			$("#tijiao").hide();
			$("#shenqingshijian").hide();
			
			$("#toid").text(data.tboverRequest.toId);
			$("#tName").text(data.tboverRequest.tbTask.TName);
			$("#tContext").text(data.tboverRequest.tbTask.TContext);
			$("#tId").text(data.tboverRequest.tbTask.TId);
			$("#applyPerson").text(data.tboverRequest.c);
			$("#tPerson").text(data.cuname);
			var nowTime = new Date();
			$("#tTime").text(nowTime.toLocaleString());     //new 一个js 时间填充
			$("#reason").text(data.tboverRequest.toReason);			
//			$("#advice").text(data.tboverRequest.tbTask.THandeled);
		}else if(data.rightString=="has_over"){        //已办结不能再申请
			$("#banjiebiao").hide();
			alert("该任务已办结不能再处理！");
		}
	}
	
	function getParams(){       //收集请求参数
		var toid=$.trim($("#toid").text());
		var tId=$.trim($("#tId").text());
//		var tTime=$.trim($("#tTime").val());
		var reason=$.trim($("#reason").val());
		var advice=$.trim($("#advice").val());        //处置建议或退办理由
		var applyPerson = $.trim($("#applyPerson").text());   //办结申请人
		var tPerson=$.trim($("#tPerson").text());    //办结人
		params = {
				"queryOption['toid']":toid,
				"queryOption['taskid']":tId,
//		 		"queryOption['toTime']":tTime,
				"queryOption['toReason']":reason,	
				"queryOption['advice']":advice,	
				"queryOption['tPerson']":tPerson,	
				"queryOption['applyPerson']":applyPerson	
				};
		return params;
	}
	
	function agreeAjax(d){
		$.ajax({
			type : "post",
			url: "lzw/TaskOver_over.action",
			data : d,
			success : function(data){
			alert(data.message);
		}
       });
	}
	
	function disagreeAjax(d){
		$.ajax({
			type : "post",
			url: "lzw/TaskOver_disagree.action",
			data : d,
			success : function(data){
			alert(data.message);
		}
       });
	}
	
//	function RequestAjax(d){
//		$.ajax({
//			type : "post",
//			url: "lzw/TaskOver_request.action",
//			data : d,
//			success : function(data){
//			alert(data.message);
//		}
//       });
//	}
	
	
	function DirectorToOverAjax(d){
		$.ajax({
			type : "post",
			url: "lzw/TaskOver_directToOver.action",
			data : d,
			success : function(data){
			alert(data.message);
		}
       });
	}
	
	//办结
	$("#agree").click(function(){
//		document.all.reason.removeAttribute('disabled');
		document.all.advice.removeAttribute('disabled');
		$("#banjiebutton").hide();
		$("#tijiao").show();
		$("#post").hide();
		$("#post3").hide();
		$("#post2").show();
		});
	
     $("#post2").click(function(){
       document.all.reason.removeAttribute('disabled');
	   var advice=$.trim($("#advice").val());
		if(advice==""){
			  alert("请认真填写办结表各项内容！");
			  return;
		  }
		if(!confirm("确定要办结吗？"))
		{
			return;
		}else{
		   agreeAjax(getParams());
		   window.setTimeout(window.parent.location.href("/ag/zhh/taskOver_request_main.jsp"),2000);
		  }
	});
	
	
	//退办
	$("#disagree").click(function(){
//		document.all.reason.removeAttribute('disabled');
		document.all.advice.removeAttribute('disabled');
		$("#banjiebutton").hide();
		$("#tijiao").show();
		$("#post2").hide();
		$("#post").hide();
		$("#post3").show();
	  });
	
//		var tTime=$.trim($("#tTime").val());
		$("#post3").click(function(){
		document.all.reason.removeAttribute('disabled');
	     var advice=$.trim($("#advice").val());
		if(advice==""){
			  alert("请认真填写办结表各项内容！");
			  return;
		  }
		if(!confirm("确定要退办吗？"))
		{
			return;
		}else{
		    disagreeAjax(getParams());
		    window.setTimeout(window.parent.location.href("/ag/zhh/taskOver_request_main.jsp"),2000);
		  }
		});
	
//	//返回
//	$("#return").click(function(){
//		 window.location.href="/ag/lzw/task_over_request_list.jsp";       
//		});
	
	
	//指挥长办结自己的任务
	$("#request").click(function(){
		document.all.advice.removeAttribute('disabled');
//		document.all.reason.removeAttribute('disabled');
//		$("#reason").attr("disabled","true");
		$("#banjiedanhao").hide();
	    $("#banjierenheshijian").show();
	    $("#chuzhi").show();
	    $("#shenqingliyou").hide();
	    $("#shenqingren").hide();
	    var nowTime = new Date();
		$("#tTime").text(nowTime.toLocaleString());
	    $("#shenqingshijian").hide();
	    //$("#request2").hide();
		
		$("#requestdiv").hide();
		$("#tijiao").show();
		$("#post2").hide();
		$("#post3").hide();
		$("#post").show();
		});
	
	    $("#post").click(function(){
	    var advice=$.trim($("#advice").val());
		if(advice==""){
			  alert("请认真填写办结表各项内容！");
			  return;
		  }
		if(!confirm("确定要办结吗？"))
		{
			return;
		}else{
		   DirectorToOverAjax(getParams());
		   window.setTimeout(window.parent.location.href("/ag/zhh/taskOver_request_main.jsp"),2000);
		  }
	});

});	

